﻿using Orchard.ContentManagement;
using Orchard.Environment.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace F2B.Orchard.Schedule.Models
{
    public class ScheduleOccurrence: IComparable<ScheduleOccurrence>
    {
        public ScheduleOccurrence(SchedulePart schedule, DateTime start)
        {
            Source = schedule.ContentItem;
            Start = start;
            AllDay = schedule.AllDay;

            if (!schedule.AllDay) Start += schedule.StartTime;
            End = Start + schedule.Duration;

            if (schedule.AllDay) End = End.AddSeconds(-1);
        }

        public IContent Source { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public bool AllDay { get; set; }

        public int CompareTo(ScheduleOccurrence other)
        {
            return Math.Sign((Start - other.Start).Ticks);
        }
    }
}